import { _decorator, Label, size, Sprite, UITransform } from 'cc';
import { Ab_BasePopUp_bA } from '../../../A-FRAME/component/ui.pop-up';
import Ab_GameAssets_bA from '../../manager/game.assets';
import type { Ab_Popup_bA } from '../page/popup';
import { Ab_Guide_bA } from '../page/guide';
import Ab_GameDC_bA from '../../manager/data.game.center';
import { Ab_DataTransfer_bA } from '../../../A-FRAME/A-LIB/lib.b.data';
const { ccclass, property } = _decorator;

@ccclass('Ab_Victory_bA')
export class Ab_Victory_bA extends Ab_BasePopUp_bA<typeof Ab_Popup_bA, null> {
	protected Ab_default_return_bA: null;

	private lbl_round: Label;

	protected Ab_initAfterOnLoad_bA(){
		this.Ab_renderLocalUI_bA();
		this.lbl_round = this.node.getChildByName('lbl-round').getComponent(Label);
	}

	public Ab_onShow_bA(round: number){
		Ab_BasePopUp_bA.Ab_jelly_enter_bA(this.node);
		this.lbl_round.string = Ab_GameAssets_bA.Ab_getLangText_bA(0, round);

		this.Ab_initGuide_bA();

		this.Ab_guide_done_bA
		.then(()=>abi.Ab_delay_bA(1.5, 'end'))
		.then(()=>Ab_BasePopUp_bA.Ab_jelly_leave_bA(this.node))
		.then(()=>this.Ab_close_bA(null));
	}

	private Ab_renderLocalUI_bA(){
		let ui_head = this.node.getChildByName('head').getComponent(UITransform);
		let head_size = size(
			this.node.getChildByName('background-head').getComponent(UITransform).width,
			ui_head.height
		);

		let sframe = Ab_GameAssets_bA.Ab_getLangTexture_bA(6);

		let scale = Math.min(head_size.width/sframe.originalSize.width, head_size.height/sframe.originalSize.height);

		ui_head.getComponent(Sprite).spriteFrame = sframe;

		ui_head.setContentSize(
			sframe.originalSize.width * scale,
			sframe.originalSize.height * scale
		);
	}

	private Ab_guide_done_bA: Promise<'end'>;
	private async Ab_initGuide_bA(){
		let np = new abi.Ab_NudityPromise_bA<'end'>();
		this.Ab_guide_done_bA = np.Ab_promise_bA;
		if(Ab_GameDC_bA.Ab_checkGuideID_bA(6)){
			np.Ab_resolve_bA('end');
			return void 0;
		}

		Ab_GameDC_bA.Ab_Trigger_bA.Ab_HILIT_SYMBOL_bA = true;

		let np_guide = new abi.Ab_NudityPromise_bA<'end'>();
		if(Ab_GameDC_bA.Ab_Status_bA.Ab_guideInited_bA) np_guide.Ab_resolve_bA('end');
		else{
			let reg = Ab_DataTransfer_bA.Ab_follow_bA(Ab_GameDC_bA.Ab_Status_bA, 'Ab_guideInited_bA', ()=>{
				Ab_DataTransfer_bA.Ab_cancel_bA(reg);
				np_guide.Ab_resolve_bA('end');
			}, false);
		}
		await np_guide.Ab_promise_bA;

		Ab_Guide_bA.Ab_Wait_bA(5).then(()=>Ab_Guide_bA.Ab_Show_bA(6))

		Ab_Guide_bA.Ab_Wait_bA(6, true).then(()=>{
			Ab_GameDC_bA.Ab_Trigger_bA.Ab_HILIT_SYMBOL_bA = false;
			this.Ab_pop_bA.Ab_Free_bA().then(()=>np.Ab_resolve_bA('end'));
		});
	}
}

